#region Terms of Usage
/*
 * Copyright 2006 Sameera Perera
 *
 *  Licensed under the Apache License, Version 2.0 (the "License");
 *  you may not use this file except in compliance with the License.
 *  You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 *  Unless required by applicable law or agreed to in writing, software
 *  distributed under the License is distributed on an "AS IS" BASIS,
 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *  See the License for the specific language governing permissions and
 *  limitations under the License.
 *
 */
#endregion

using System;
using System.Collections.Generic;
using System.Text;
using System.ComponentModel;

namespace needle.Services.soab.RequestQueue
{
    public class ServiceResponse
    {
        private readonly object data;
        private readonly ServiceRequest request;

        /// <summary>
        /// Gets the data asociated with the reponse
        /// </summary>
        public object Data { get { return data; } }

        // Data returned after the asynchronous request has completed.
        private readonly AsyncCompletedEventArgs asyncData;

        /// <summary>
        /// Gets whether the operation was cancelled.
        /// </summary>
        public bool Cancelled { get { return asyncData.Cancelled; } }

        /// <summary>
        /// Gets the exception that occured during the operation.
        /// </summary>
        public Exception Error { get { return asyncData.Error; } }

        /// <summary>Gets the <see cref="ServiceRequest"/> that caused this response.</summary>
        public ServiceRequest Request { get { return this.request; } }

        /// <summary>Constructs a new <see cref="ServiceResponse"/>.</summary>
        /// <param name="data">The return value from the remote method.</param>
        /// <param name="request">The <see cref="ServiceRequest"/> that caused this response.</param>
        /// <param name="e">Event information on the ayscnchrous invokation.</param>
        public ServiceResponse(object data, ServiceRequest request, AsyncCompletedEventArgs e)
        {
            this.data       = data;
            this.request    = request;
            this.asyncData  = e;
        }
    }
}
